<!--
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-11-20 11:24:04
 * @LastEditors: huangtianyang
 * @LastEditTime: 2024-02-26 16:02:46
 * @FilePath: \cxl-driving-training\src\components\Operation.vue
-->
<!-- 驾校编辑 班别编辑 模板 -->
<template>
    <div class="operation-box">
        <titleVue :title="title" big="true" />
        <titleVue title="列表配置" v-if="smallTitle" />
        <div class="">
            <slot name="config" />
        </div>
        <titleVue title="详情配置" v-if="smallTitle" />
        <div class="detailed-config">
            <div class="left-nav">
                <div>
                    <span class="" v-for="item in detailedList" :key="item.title" @click="anchor(item.slotName)">
                        {{ item.title }}
                    </span>
                </div>
            </div>
            <div class="right-content">
                <template v-for="item in detailedList" :key="item">
                    <titleVue :title="item.title" small="true" :id="item.slotName" />
                    <slot :name="item.slotName" />
                </template>
            </div>
        </div>
        <!-- 取消 保存 -->
        <div class="operation">
            <el-button @click="$emit('cancel')"> {{ disabled ? '返回' : '取消' }}</el-button>
            <el-button type="primary" @click="$emit('save')" v-if="!disabled">保存</el-button>
        </div>
    </div>
</template>
<script setup lang="ts">
import titleVue from '@/components/title/Index.vue'

const props = defineProps(['title', 'detailedList', 'smallTitle', 'disabled'])
const emits = defineEmits(['cancel', 'save'])

//锚点滚动
const anchor = (id: string) => {
    document.getElementById(id)?.scrollIntoView({ behavior: 'smooth', block: 'start', inline: 'nearest' })
}
</script>
<style scoped lang="scss">
.detailed-config {
    width: 100%;
    display: flex;
    position: relative;
    .left-nav {
        width: 100px;

        > div {
            position: sticky;
            top: 0;
            left: 0;
        }
        span {
            display: block;
            width: 100%;
            line-height: 32px;
            position: relative;
            box-sizing: border-box;
            padding: 0 0 0 10px;
            cursor: pointer;
            &::before {
                content: '';
                display: block;
                width: 7px;
                height: 7px;
                border-radius: 50%;
                background-color: #333;
                position: absolute;
                top: 13px;
                left: 0;
            }
            &:not(:last-child) {
                &::after {
                    content: '';
                    display: block;
                    width: 1px;
                    height: 32px;
                    border-radius: 50%;
                    background-color: #333;
                    position: absolute;
                    top: 16px;
                    left: 3px;
                }
            }
        }
    }
    .right-content {
        width: calc(100% - 100px);

        .class-image {
            display: flex;
            flex-wrap: wrap;
            > div {
                margin: 0 16px 16px 0;
            }
        }
    }
}

.operation {
    display: flex;
    justify-content: center;
    margin: 50px 0 100px 0;
    > button {
        margin: 0 30px;
    }
}
</style>
